﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Netfraction.ClientInterface
{
    public class PeerEventArgs : EventArgs
    {
        public Identity Identity { get; set; }
        public bool IsLocalClient { get; set; }

        public PeerEventArgs(Identity identity, bool isLocalClient)
        {
            this.Identity = identity;
            this.IsLocalClient = isLocalClient;
        }
    }

    public class HubNameEventArgs : EventArgs
    {
        public string HubName { get; set; }

        public HubNameEventArgs(string newName)
        {
            this.HubName = newName;
        }
    }

    public delegate void PeerChangedEventHandler(PeerEventArgs e);
    public delegate void HubNameChangedEventHandler(HubNameEventArgs e);

    public static class Peers
    {
        public static event PeerChangedEventHandler OnPeerOnline;
        public static event PeerChangedEventHandler OnPeerChanged;
        public static event PeerChangedEventHandler OnPeerOffline;
        public static event HubNameChangedEventHandler OnHubNameChanged;

        public static void PeerOnline(Identity identity, bool isLocalClient)
        {
            if (OnPeerOnline != null)
                OnPeerOnline(new PeerEventArgs(identity, isLocalClient));
        }

        public static void PeerChanged(Identity identity, bool isLocalClient)
        {
            if (OnPeerChanged != null)
                OnPeerChanged(new PeerEventArgs(identity, isLocalClient));
        }

        public static void PeerOffline(Identity identity, bool isLocalClient)
        {
            if (OnPeerOffline != null)
                OnPeerOffline(new PeerEventArgs(identity, isLocalClient));
        }

        public static void HubNameChanged(string newName)
        {
            if (OnHubNameChanged != null)
                OnHubNameChanged(new HubNameEventArgs(newName));
        }
    }
}
